#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <linux/watchdog.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <assert.h>
#include <math.h>
#include <sys/stat.h>
#include <sys/time.h>
#include "wdt.h"

int main()
{
	int dev;
	int timeout = 30; 

	dev = open("/dev/watchdog", O_RDONLY);
	if (dev <= 0) {
		printf("watchdog device open fail\n");
		exit(0);
	}

	ioctl(dev, WDIOC_SETTIMEOUT, &timeout);

	//ioctl(dev, WDIOC_GETSTATUS, &timeout);
	//printf("WDIOC_GETSTATUS = %d\n", timeout);

	ioctl(dev, WDIOC_GETTIMEOUT, &timeout);
	printf("WDIOC_GETTIMEOUT = %d\n", timeout);


	write(dev, "\0", 1);
	
	while(1)
	{
		// Feed WatchDog
		if(dev != -1)
		{
			write(dev, "\0", 1);
		}
		#define msleep(ms) usleep(ms*1000)
		msleep(2000);
	}
	
	close(dev);

	return 0;
}
